<template>
    <Page>
        <div class="search">
            <el-form :inline="true" :model="params" class="demo-form-inline">
                <el-form-item label="结算状态">
<!--                    <el-input v-model="params.user" placeholder="请输入" size="small"></el-input>-->
                    <el-select v-model="params.settStatus" :clearable="true" size="small" placeholder="请选择结算状态">
                        <el-option
                            v-for="(item, index) in settStatusList"
                            :key="item.label"
                            :label="item.name"
                            :value="item.label"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="经销商">
                    <el-input v-model="params.mchParam" placeholder="请输入经销商" size="small"></el-input>
                </el-form-item>
                <el-form-item label="关键字">
                    <el-input v-model="params.searchKey" placeholder="请输入关键字" size="small"></el-input>
                </el-form-item>
                <el-form-item label="日期">
                    <el-date-picker
                        v-model="datetime"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        size="small"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        @change="changeDateTime"
                        style="width:250px;"
                    ></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="searchData">查询</el-button>
                    <el-button type="primary" size="small" @click="resetSearch" plain>重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="datalist">
            <div class="table-header"></div>
            <div class="table-list">
                <el-table
                    :data="listData.list"
                    stripe
                    style="width:100%"
                    width="100%"
                    :highlight-current-row="false"
                    size="small"
                    :header-cell-style="{background:'#FAFAFA',color:'#666', fontSize:'13px'}"
                >
                    <el-table-column prop="settleDate" label="结算时间" align="center"></el-table-column>
                    <el-table-column prop="settleTrxNo" label="结算单号" align="center"></el-table-column>
                    <el-table-column prop="mchInfo" label="经销商编号/名称" align="center"></el-table-column>
                    <el-table-column prop="platAmount" label="平台结算（元）" align="center"></el-table-column>
                    <el-table-column prop="mchAmount" label="经销商结算（元）" align="center"></el-table-column>
                    <el-table-column prop="mchAccount" label="经销商账户" align="center"></el-table-column>
                    <el-table-column prop="settStatus" label="结算状态" align="center">
                        <template slot-scope="scope">
                            <span>{{scope.row.settStatus|statusToName(settStatusList)}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="remark" label="备注" align="center"></el-table-column>
                </el-table>
                <div class="list-paginate">
                    <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="params.currPage"
                        :page-size="params.pageSize"
                        :total="listData.totalCount"
                        @current-change="changePage"
                    ></el-pagination>
                </div>
            </div>
        </div>
    </Page>
</template>
<script>
import Page from "@/components/page/Page";
export default {
    data(){
        return {
            params:{
                settStatus:null,    // 结算状态
                mchParam:null,      // 经销商
                searchKey:null,     // 关键词
                dateBegin:null,     // 开始日期
                dateEnd:null,       // 结束日期
                currPage:1,
                pageSize:15,
            },
            listData:{
                currPage: 0,
                list: [],
                pageSize: 0,
                totalCount: 0,
                totalPage: 0,
            },
            settStatusList:[
                {label:-1, name:'结算失败'},
                {label:0, name:'未结算'},
                {label:1, name:'结算成功'},
            ],
            datetime:[],
        }
    },
    mounted() {
        this.initData();
    },
    methods:{
        // 初始化数据
        initData(){
            this.$http.get("/api/altmch/settList", {params:this.params}).then(result => {
                if(result.code == 200){
                    this.listData = result.data;
                }else{
                    this.$message.error(result.msg);
                }
            });
        },
        // 执行查询
        searchData(){
            this.params.currPage = 1;
            this.initData();
        },
        // 重置查询
        resetSearch(){
            ['settStatus','mchParam','searchKey','dateBegin','dateEnd'].forEach(item => {
                this.params[item] = null;
            });
            this.datetime = [];
            this.searchData();
        },
        // 选择日期
        changeDateTime(e){
            this.datetime = e;
            const [dateBegin, dateEnd] = e;
            this.params.dateBegin = dateBegin;
            this.params.dateEnd = dateEnd;
        },
        // 分页点击
        changePage(e){
            this.params.currPage = e;
            this.initData();
        },
    },
    filters:{
        // 状态转中文
        statusToName(status, statusList){
            let statusName = '';
            statusList.forEach((item, index) => {
                if(item.label == parseInt(status)){
                    statusName = item.name;
                }
            });
            return statusName;
        },
    },
    components:{
        Page,
    }
}
</script>
<style lang="less" scoped>
    .page{

    }
</style>
